﻿Public Class clsWorkshopCurrent

    Public Function SaveData(pgd_xj_sys_id As String, support_model As String, workshop As String, current_section As String, plan_num As Integer, finished_num As Integer) As Integer
        Dim szSql As String = String.Empty
        Dim rtn As Integer
        szSql = String.Empty
        szSql &= "SELECT * FROM sf.b_workshop_current WHERE factory_id = ? and workshop = ? and current_section = ? "
        Dim dtxj As DataTable = DBacs.ExecuteSql(szSql, -1, "TS", workshop, current_section)
        If dtxj.Rows.Count = 0 Then
            szSql = String.Empty
            szSql &= "INSERT INTO sf.b_workshop_current( factory_id, workshop, current_section, b_pgd_sys_id, support_model, update_time,plan_quantity,finished_quantity) "
            szSql &= "VALUES ( ? , ? , ? , ? , ? , (SELECT CURRENT_TIMESTAMP(6)),?,?); "
            rtn = DBacs.ExecuteUpdateSql(szSql, -1, "TS", workshop, current_section, pgd_xj_sys_id, support_model, plan_num, finished_num)
        Else
            szSql = String.Empty
            szSql &= "UPDATE sf.b_workshop_current SET b_pgd_sys_id = ?, support_model = ?, update_time = (SELECT CURRENT_TIMESTAMP(6)) ,plan_quantity=?,finished_quantity=?"
            szSql &= "WHERE factory_id = ? and workshop = ? and current_section = ? "
            rtn = DBacs.ExecuteUpdateSql(szSql, -1, pgd_xj_sys_id, support_model, plan_num, finished_num, "TS", workshop, current_section)
        End If
        Return rtn
    End Function

    Public Function updateDataClear(workshop As String, current_section As String) As Integer
        Dim szSql As String = "UPDATE sf.b_workshop_current SET b_pgd_sys_id = ?, support_model = ?, update_time = (SELECT CURRENT_TIMESTAMP(6)) ,plan_quantity=?,finished_quantity=?"
        szSql &= "WHERE factory_id = ? and workshop = ? and current_section = ? "
        Return DBacs.ExecuteUpdateSql(szSql, -1, 0, DBNull.Value, 0, 0, "TS", workshop, current_section)
    End Function

    Public Function GetListByWorkShopIdAndCurrentSection(ws_id As String, current_section As String) As DataTable
        Dim szSql As String = "SELECT * FROM sf.b_workshop_current where workshop = ? and current_section = ? "
        Return DBacs.ExecuteSql(szSql, -1, ws_id, current_section)
    End Function
End Class
